#include "Expr.h"

void Expr::gen(Label * s, Label * t)
{
	Stmt::gen(s, t);
	reduce();
}

Expr* Expr::reduce()
{
	return this;
}

void Expr::jumping(Label * t, Label * f)
{
	Constant* zero = new Constant(new Token(tag::DIGIT,"0"));
	Expr* T = reduce();
	RTL::putData(new Token(tag::NE,"!="), T, zero, t);
	RTL::putData(new Token(tag::JUMP, "jmp"), NULL, NULL, f);
}


Expr::Expr()
{
}

Expr::Expr(Token * op)
{
	this->op = op;
}


Expr::~Expr()
{
}



Constant::Constant(Token* token)
{
	this->op = token;
	this->value = atoi(token->name.c_str());
}


Constant::~Constant()
{
}

string Constant::ToRTL()
{
	return this->op->name;
}
